﻿var currentPage = 1; // 当前页
var pageSize = 18; // 每页显示多少条
var pageall = 0; // 总页数
var total = 0; // 总记录数
var type_id = 0;

// 读取列表
$(function() {
    var typeid = LexunJS.GetQueryString("typeid")
    type_id = LexunJS.GetQueryString("type");

    if (typeid == 2) {
        document.getElementById("rdAlert2").checked = true;
        document.getElementById("rdAlert1").checked = false;
    }
    else {
        document.getElementById("rdAlert1").checked = true;
        document.getElementById("rdAlert2").checked = false;
    }
    showList(currentPage);
});

// 切换类型搜索
function search() {
    $("#divList").html(""); // 清空列表
    $("#divPage").html(""); // 清空分页

    showList(1);
}

// 条件查询列表
function showList(currentPage) {
    var typeid = 1;

    if (document.getElementById("rdAlert2").checked)
        typeid = 2;
    $("#divList").html("<img src=\"../images/loading.gif\" />"); // 清空列表

    // typeid: 1今日提醒 2所有提醒
    if (typeid == 2) {
        $.ajax({
            type: 'POST',
            url: '../Handler/HandlerAlert.ashx',
            data: 'act=alertlist&page=' + currentPage + '&pagesize=' + pageSize,
            timeout: '10000',
            error: function() {
                alert("系统繁忙,请稍候后试！");
            }, success: function(json) {
                listCallBack1(json);
            }
        });
    }
    else {
        $.ajax({
            type: 'POST',
            url: '../Handler/HandlerAlert.ashx',
            data: 'act=todayalert&page=' + currentPage + '&pagesize=' + pageSize,
            timeout: '10000',
            error: function() {
                alert("系统繁忙,请稍候后试！");
            }, success: function(json) {
                listCallBack1(json);
            }
        });
    }

}

/*
功能: 将返回的json数据进行排版
json: json数据
*/
function listCallBack1(response) {
    var json = eval("(" + response + ")");
    var record = json.record;

    if (record == null || record.length == 0) {
        $("#divList").html("<font color='red'>&nbsp;系统内暂无您查询的信息!</font>");
        return;
    }
    var curUserID = $('#curUserID').val();
    var page = json.page;

    currentPage = page.currentpage;
    pageall = parseInt(page.pageall);
    total = page.total;

    $("#divList").html("");
    var arr = [];
    arr.push("<table id='table1' width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
    arr.push("<tr>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("客/盘提醒</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("客/盘编号</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("添加人</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("部门</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("提醒时间</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("提醒类型</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("提醒内容</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("处理标志</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("处理时间</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("处理人</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("处理部门</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("操作</td>");

    arr.push("</tr>");
    for (var i = 0; i < record.length; i++) {
        if (i % 2 == 0)
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#FFFFFF' style='cursor: pointer;' onclick=\"selectedTr('" + record[i].id + "')\" >");
        else
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#EEEDED' style='cursor: pointer;' onclick=\"selectedTr('" + record[i].id + "')\" >");
       
        arr.push("<td height='25'  class='STYLE6'>");
        if (record[i].type == 1 && record[i].housingid > 0) {
            arr.push("<font color='red'>盘源提醒</font></td>");
        }
        else if (record[i].type == 2 && record[i].housingid > 0) {
            arr.push("<font color='blue'>客源提醒</font></td>");
        }
        else {
            arr.push("其它提醒</td>");
        }
        arr.push("<td height='25'  class='STYLE6'>");
        if (record[i].type == 1 && record[i].housingid > 0) {
            if (type_id == 1)
                arr.push(" <a href='javascript:showHousing1Dialog(\"" + record[i].housingid + "\", 8);'>" + record[i].housingid + "</a></td>");

            else
                arr.push(" <a href='javascript:showHousingDialog(\"" + record[i].housingid + "\", 8);'>" + record[i].housingid + "</a></td>");
        }
        else if (record[i].type == 2 && record[i].housingid > 0) {
            if (type_id == 1)
                arr.push(" <a href='javascript:showCustomer1Dialog(\"" + record[i].housingid + "\", 4);'>" + record[i].housingid + "</a></td>");

            else
                arr.push(" <a href='javascript:showCustomerDialog(\"" + record[i].housingid + "\", 4);'>" + record[i].housingid + "</a></td>");
        }
        else {
            arr.push("0</td>");
        }
        arr.push("<td height='25'  class='STYLE6'>");
        arr.push("" + record[i].adduser + "</td>");
        arr.push("<td height='25'  class='STYLE6'>");
        arr.push("" + record[i].adddept + "</td>");
        arr.push("<td height='25'  class='STYLE6'>");
        arr.push("" + record[i].alertdate + "</td>");
        arr.push("<td height='25'  class='STYLE6'>");
        arr.push("" + record[i].alerttype + "</td>");
        arr.push("<td height='25'  class='STYLE6' style='text-align: left;padding-left:10px;'>");
        arr.push("" + record[i].alertcontent + "</td>");
        if (record[i].dflag == 1) {
            arr.push("<td height='25'  class='STYLE6'>");
            arr.push("<font color='blue'>已处理</font></td>");
        } else {
            arr.push("<td height='25'  class='STYLE6'>");
            arr.push("<font color='red'>未处理</font></td>");
        }

        arr.push("<td height='25'  class='STYLE6'>");
        if (record[i].dflag == 1) {
            arr.push("" + record[i].ddate + "</td>");
        } else {
            arr.push("</td>");
        }
        arr.push("<td height='25'  class='STYLE6'>");
        arr.push("" + record[i].duser + "</td>");
        arr.push("<td height='25'  class='STYLE6'>");
        arr.push("" + record[i].ddept + "</td>");
        arr.push("<td height='25'  class='STYLE6'>");


        if (record[i].adduserid == curUserID) {
            arr.push("<a href='javascript:DealAlert(" + record[i].type + "," + record[i].id + ") '>处理</a>   ");
            arr.push("<a href='javascript:delAlert(" + record[i].type + "," + record[i].id + ")'>删除</a>");
        }
        arr.push("</td>");
        arr.push("</tr>");
    }
    arr.push("</table>");
    $("#divList").html(arr.join('')); // 显示列表
    $("#divPage").html(""); // 清空
    if (pageall > 1) {
        var pageHtml = LexunJS.showPage2(currentPage, pageall, "showList"); // 分页
        $("#divPage").html(pageHtml);
    }

}


// 弹出窗口,查看某匹配出的房源详细
function showHousingDialog(id, tagNo) {
    if (tagNo == null) {
        tagNo = 3;
    }
    var path = "../PM/HousingDetail.aspx?id=" + id + "&tagNo=" + tagNo;
    var parameter = "盘源详情";
    var style = "dialogWidth:800px; dialogHeight:550px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";

//    window.open(path, parameter, style);
    self.parent.closeTab(' 盘源详情');
    self.parent.addTab(' 盘源详情', path, 'icon-nav');
}

// 弹出窗口
function showCustomerDialog(id, tagNo) {
    if (tagNo == null) {
        tagNo = 2;
    }
    var path = "../CM/CustomerDetail.aspx?id=" + id + "&tagNo=" + tagNo;
    var parameter = "客源详情";
    var style = "dialogWidth:600px; dialogHeight:450px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";

//    window.open(path, parameter, style);
    self.parent.closeTab(' 客源详情');
    self.parent.addTab(' 客源详情', path, 'icon-nav');

}


// 弹出窗口,查看某匹配出的房源详细
function showHousing1Dialog(id, tagNo) {
    if (tagNo == null) {
        tagNo = 3;
    }
    var path = "../PM/HousingDetail.aspx?id=" + id + "&tagNo=" + tagNo;
    var parameter = "盘源详情";

    var style = "left = 50, screenX = 0, top = 50, screenY = 0, resizable = yes, scrollbars = yes,width=750px, height=450px,Toolbar=no,Location=no,Direction=no,Resizeable=no";
    window.open(path, parameter, style);
}

// 弹出窗口
function showCustomer1Dialog(id, tagNo) {
    if (tagNo == null) {
        tagNo = 2;
    }
    var path = "../CM/CustomerDetail.aspx?id=" + id + "&tagNo=" + tagNo;
    var parameter = "客源详情";
    var style = "left = 50, screenX = 0, top = 50, screenY = 0, resizable = yes, scrollbars = yes,width=750px, height=450px,Toolbar=no,Location=no,Direction=no,Resizeable=no";
    window.open(path, parameter, style);

}


//添加提醒
function ShowDioagInfo() {
    var path = "../PM/EstateInfo.aspx?id=0";
    var parameter = "添加提醒";
    var style = "dialogWidth:538px; dialogHeight:430px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
    window.showModalDialog(path, parameter, style);
    window.location.href = "AlertManager.aspx?typeid=2";
}


//处理提醒
function DealAlert(typeid, id) {
    // ajax修改
    if (typeid == 1) {
        $.ajax({
            type: 'POST',
            url: '../Handler/HandlerHousing.ashx',
            data: 'act=UpdateAlert&id=' + id,
            timeout: '10000',
            error: function() {
                alert("处理失败！");
            },
            success: function(outmsg) {
                if (outmsg < 1) {
                    alert("处理失败！");
                }
                showList(currentPage);
            }
        });
    }
    else if (typeid == 2) {
        $.ajax({
            type: 'POST',
            url: '../Handler/HandlerCustomer.ashx',
            data: 'act=p_CustomerAlert_Update&id=' + id,
            timeout: '10000',
            error: function() {
                alert("处理失败！");
            },
            success: function(outmsg) {
                if (outmsg < 1) {
                    alert("处理失败！");
                }
                showList(currentPage);
            }
        });

    }
}


// 删除提醒
function delAlert(typeid, id) {
    // ajax删除
    if (typeid == 1) {
        $.ajax({
            type: 'POST',
            url: '../Handler/HandlerHousing.ashx',
            data: 'act=delAlert&id=' + id,
            timeout: '10000',
            error: function() {
                alert("删除失败！");
            },
            success: function(outmsg) {
                alert(outmsg);
                showList(currentPage)
            }
        });
    }
    else if (typeid == 2) {
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerCustomer.ashx',
        data: 'act=DeleteCustomerAlert&id=' + id,
        timeout: '10000',
        error: function() {
            alert("删除失败！");
        },
        success: function(outmsg) {
            alert(outmsg);
            showList(currentPage)
        }
    });
    }


}

















// 单选
function cbSelect(obj, objvalue) {
    if (obj.checked) {
        LexunJS.addOrCutData(1, "hID", objvalue);
    }
    else {
        LexunJS.addOrCutData(0, "hID", objvalue);
    }
}

// 全选
function cbSelectAll() {
    document.getElementById("hID").value = "";
    var cbAll = document.getElementById("checkboxAll");
    var checkList = document.getElementsByTagName("input");

    if (cbAll.checked) {
        for (var i = 0; i < checkList.length; i++) {
            if (checkList[i].type == "checkbox") {
                checkList[i].checked = true;
                if (parseInt(checkList[i].id) > 0) LexunJS.addOrCutData(1, "hID", checkList[i].id);
            }
        }
    }
    else {
        for (var i = 0; i < checkList.length; i++) {
            if (checkList[i].type == "checkbox") {
                checkList[i].checked = false;
                if (parseInt(checkList[i].id) > 0) LexunJS.addOrCutData(0, "hID", checkList[i].id);
            }
        }
    }
}

// 选中某行
function selectedTr(id) {
    $("tr").removeClass("selected");
    $("#tr_" + id).addClass("selected");
}

// 审核
function deal() {
    var IDList = document.getElementById("hID").value;
    if (IDList == "") {
        alert("请先选择您要审核的行！");
        return false;
    }

    hiConfirm("您确定要审核该行，请谨慎操作！", "确认框", function(result) {
        if (result) {

            var typeid = 1;
            if (document.getElementById("rdEstate2").checked)
                typeid = 2;
            else if (document.getElementById("rdEstate3").checked)
                typeid = 3;

            if (typeid == 1) {
                $.ajax({
                    type: 'POST',
                    url: '../Handler/HandlerCheck.ashx',
                    data: 'act=estate_check&id=' + IDList,
                    timeout: '10000',
                    error: function() {
                        alert("楼盘审核失败！");
                    }, success: function(outmsg) {
                        $("#hID").val("");
                        alert(outmsg);
                        showList(currentPage);
                    }
                });
            } else if (typeid == 2) {
                $.ajax({
                    type: 'POST',
                    url: '../Handler/HandlerCheck.ashx',
                    data: 'act=build_check&id=' + IDList,
                    timeout: '10000',
                    error: function() {
                        alert("栋阁审核失败！");
                    }, success: function(outmsg) {
                        $("#hID").val("");
                        alert(outmsg);
                        showList(currentPage);
                    }
                });
            } else if (typeid == 3) {
                $.ajax({
                    type: 'POST',
                    url: '../Handler/HandlerCheck.ashx',
                    data: 'act=roomno_check&id=' + IDList,
                    timeout: '10000',
                    error: function() {
                        alert("房号审核失败！");
                    }, success: function(outmsg) {
                        $("#hID").val("");
                        alert(outmsg);
                        showList(currentPage);
                    }
                });
            }
        }
    });

    return false;
}

// 删除
function del() {
    var IDList = document.getElementById("hID").value;
    if (IDList == "") {
        alert("请先选择您要删除的行！");
        return false;
    }

    hiConfirm("您确定要删除该行，请谨慎操作！", "确认框", function(result) {
        if (result) {

            var typeid = 1;
            if (document.getElementById("rdEstate2").checked)
                typeid = 2;
            else if (document.getElementById("rdEstate3").checked)
                typeid = 3;

            if (typeid == 1) {
                $.ajax({
                    type: 'POST',
                    url: '../Handler/HandlerIndex.ashx',
                    data: 'act=estate_del&id=' + IDList,
                    timeout: '10000',
                    error: function() {
                        alert("楼盘删除失败！");
                    }, success: function(outmsg) {
                        $("#hID").val("");
                        alert(outmsg);
                        showList(currentPage);
                    }
                });
            } else if (typeid == 2) {
                $.ajax({
                    type: 'POST',
                    url: '../Handler/HandlerIndex.ashx',
                    data: 'act=build_del&id=' + IDList,
                    timeout: '10000',
                    error: function() {
                        alert("栋阁删除失败！");
                    }, success: function(outmsg) {
                        $("#hID").val("");
                        alert(outmsg);
                        showList(currentPage);
                    }
                });
            } else if (typeid == 3) {
                $.ajax({
                    type: 'POST',
                    url: '../Handler/HandlerIndex.ashx',
                    data: 'act=roomno_del&id=' + IDList,
                    timeout: '10000',
                    error: function() {
                        alert("房号删除失败！");
                    }, success: function(outmsg) {
                        $("#hID").val("");
                        alert(outmsg);
                        showList(currentPage);
                    }
                });
            }
        }
    });

    return false;
}
    